package com.example.yuejian.yuejian.model;

import com.example.yuejian.yuejian.base.ModleListListener;
import com.example.yuejian.yuejian.base.ModleListener;
import com.example.yuejian.yuejian.bean.AddComment;
import com.example.yuejian.yuejian.bean.CommentList;
import com.example.yuejian.yuejian.service.CommentService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2017/10/13.
 */

public class CommentModel {
    private Retrofit retrofit;

    public CommentModel() {
        retrofit = new Retrofit.Builder()
                .addConverterFactory(GsonConverterFactory.create())
                .baseUrl(Contants.BASE_URL)
                .build();
    }
    public void Commentlist(String showid, final ModleListListener listListener)
    {
        CommentService service=retrofit.create(CommentService.class);
        Call<List<CommentList>>call=service.commentlist(showid);
        call.enqueue(new Callback<List<CommentList>>() {
            @Override
            public void onResponse(Call<List<CommentList>> call, Response<List<CommentList>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listListener.onResponse(response.body());
                } else
                    listListener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<List<CommentList>> call, Throwable t) {
                listListener.onFail(t.toString());
            }
        });
    }
    public void AddCommnet(String userid, String content, String showphoto, final ModleListener listener)
    {
        CommentService service=retrofit.create(CommentService.class);
        Call<AddComment>call=service.addComment(userid,content,showphoto);
        call.enqueue(new Callback<AddComment>() {
            @Override
            public void onResponse(Call<AddComment> call, Response<AddComment> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                } else
                    listener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<AddComment> call, Throwable t) {
                   listener.onFail(t.toString());
            }
        });
    }
}
